/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * @author yaoyuming
 * @date  2020-07-31 13:56
 */
package com.yao.mp;

import com.baomidou.mybatisplus.generator.config.IFileCreate;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.config.rules.FileType;
import lombok.extern.slf4j.Slf4j;

/**
 * @author yaoyuming
 * @date 2020/07/31 13:56
 */
@Slf4j
public class FileCreateImpl implements IFileCreate {

    @Override
    public boolean isCreate(ConfigBuilder cb, FileType fileType, String filePath) {
        // 调用默认方法创建目录
        checkDir(filePath);

        // 允许生成模板文件
        return true;
    }

    /*protected boolean isCreate(FileType fileType, String filePath) {
        ConfigBuilder cb = getConfigBuilder();
        // 自定义判断
        InjectionConfig ic = cb.getInjectionConfig();
        if (null != ic && null != ic.getFileCreate()) {
            return ic.getFileCreate().isCreate(cb, fileType, filePath);
        }
        // 全局判断【默认】
        File file = new File(filePath);
        boolean exist = file.exists();
        if (!exist) {
            file.getParentFile().mkdirs();
        }
        return !exist || getConfigBuilder().getGlobalConfig().isFileOverride();
    }
    */

}